package com.guage.producter.controller;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.guage.producter.domain.RetailHoldBook;
import com.guage.producter.result.JSONResult;
import com.guage.producter.service.IRetailHoldBookService;
import com.guage.producter.utils.SnowflakeIdWorker;
import com.pad.dpscn.daag.sdk.core.annotation.DataSendPosition;

/**
 * @desc
 * @author yangdezhao
 * @since 2024-03-08
 */
@RestController
@RequestMapping("/retailHoldBook")
@DataSendPosition
public class RetailHoldBookController {

	@Autowired
	public IRetailHoldBookService retailHoldBookService;

	/**
	 * 保存和修改操作公用此方法
	 * 
	 * @param retailHoldBook 前端传递来的实体数据
	 */
	@PostMapping(value = "/save")
	public JSONResult save(@RequestBody RetailHoldBook retailHoldBook) {
		SnowflakeIdWorker idWorker = new SnowflakeIdWorker(1, 1);
		long id = idWorker.nextId();
		java.sql.Date sqlDate = new java.sql.Date(System.currentTimeMillis());
		retailHoldBook.setHoldId(id + "");
		retailHoldBook.setHoldDueDate(sqlDate);
		retailHoldBook.setUnholdDate(sqlDate);
		retailHoldBook.setCreateDate(sqlDate);
		retailHoldBook.setFirstHoldDate(sqlDate);
		retailHoldBook.setFirstHoldDate(sqlDate);
		retailHoldBook.setFirstHoldTime(sqlDate);
		retailHoldBook.setUnholdTime(sqlDate);
		retailHoldBook.setMatnTimeStamp(sqlDate);
		retailHoldBookService.insert(retailHoldBook);
		return JSONResult.success();
	}

	/**
	 * 根据ID删除指定对象信息
	 * 
	 * @param id
	 */
	@DeleteMapping(value = "/delete/{id}")
	public JSONResult deleteById(@PathVariable("id") String id) {
		retailHoldBookService.deleteById(id);
		return JSONResult.success();
	}

	@DeleteMapping(value = "/dynamicDeleteRetailHoldBook")
	public JSONResult dynamicDeleteRetailHoldBook(@RequestBody Map<String, Object> map) {
		retailHoldBookService.dynamicDeleteRetailHoldBook(map);
		return JSONResult.success();
	}

	/**
	 * 根据ID删除指定对象信息
	 * 
	 * @param id
	 */
	@PostMapping(value = "/updateById")
	public JSONResult updateById(@RequestBody RetailHoldBook retailHoldBook) {
		java.sql.Date sqlDate = new java.sql.Date(System.currentTimeMillis());
		retailHoldBook.setUpdateDate(sqlDate);
		retailHoldBookService.updateById(retailHoldBook);
		return JSONResult.success();
	}

	@PostMapping(value = "/updateBatchById")
	public JSONResult updateBatchById(@RequestBody Map<String, String> map) {
		List<RetailHoldBook> entityList = new ArrayList<RetailHoldBook>();
		for (int i = 0; i < 5; i++) {
			RetailHoldBook retailHoldBook = new RetailHoldBook();
			if (map.get("key" + i) != null) {
				java.sql.Date sqlDate = new java.sql.Date(System.currentTimeMillis());
				retailHoldBook.setHoldId(map.get("key" + i));
				retailHoldBook.setCustNo("CUST0006");
				retailHoldBook.setAcctNo("ACCT123456789012345678" + i);
				retailHoldBook.setCcy("RMB");
				retailHoldBook.setAttrType("EF");
				retailHoldBook.setAttrCode("GH");
				retailHoldBook.setHoldLevelCd("K");
				retailHoldBook.setHoldReasonCd("002");
				retailHoldBook.setPriority(new BigDecimal(10));
				retailHoldBook.setCertNo("123456789");
				retailHoldBook.setUnholdDate(sqlDate);
				retailHoldBook.setUpdateDate(sqlDate);
				retailHoldBook.setUpdateBy("李四");
				retailHoldBook.setMatnTimeStamp(sqlDate);
				retailHoldBook.setSubAcctNo("110");
				retailHoldBook.setSubAcctSerialNo("10086");
				retailHoldBook.setStopPaymentTypeCd("N");
				retailHoldBook.setDelFlag("Y");
				retailHoldBook.setVersion(3);
				entityList.add(retailHoldBook);
			}
		}
		Boolean result = retailHoldBookService.updateBatchById(entityList);
		return JSONResult.success(result);
	}

	// 根据ID查询对象详情信息
	@GetMapping(value = "/selectById/{id}")
	public JSONResult get(@PathVariable("id") String id) {
		return JSONResult.success(retailHoldBookService.selectById(id));
	}

	/**
	 * 查看所有对象数据（不分页）
	 */
	@GetMapping(value = "/list")
	public JSONResult list() {
		return JSONResult.success(retailHoldBookService.selectList(null));
	}
}